package me.zhengjie.modules.inspection.rest;

import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.inspection.domain.InspectionTemplateItemRel;
import me.zhengjie.modules.inspection.service.InspectionTemplateItemRelService;
import me.zhengjie.modules.inspection.service.dto.InspectionTemplateItemRelQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
* @author xuyukun
* @date 2019-07-07
*/
@RestController
@RequestMapping("api")
public class InspectionTemplateItemRelController {

    @Autowired
    private InspectionTemplateItemRelService inspectionTemplateItemRelService;

    @Log("查询InspectionTemplateItemRel")
    @GetMapping(value = "/inspectionTemplateItemRel")
    @PreAuthorize("hasAnyRole('ADMIN','INSPECTIONTEMPLATEITEMREL_ALL','INSPECTIONTEMPLATEITEMREL_SELECT')")
    public ResponseEntity getInspectionTemplateItemRels(InspectionTemplateItemRelQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity(inspectionTemplateItemRelService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @Log("新增InspectionTemplateItemRel")
    @PostMapping(value = "/inspectionTemplateItemRel")
    @PreAuthorize("hasAnyRole('ADMIN','INSPECTIONTEMPLATEITEMREL_ALL','INSPECTIONTEMPLATEITEMREL_CREATE')")
    public ResponseEntity create(@Validated @RequestBody InspectionTemplateItemRel resources){
        return new ResponseEntity(inspectionTemplateItemRelService.create(resources),HttpStatus.CREATED);
    }

    @Log("修改InspectionTemplateItemRel")
    @PutMapping(value = "/inspectionTemplateItemRel")
    @PreAuthorize("hasAnyRole('ADMIN','INSPECTIONTEMPLATEITEMREL_ALL','INSPECTIONTEMPLATEITEMREL_EDIT')")
    public ResponseEntity update(@Validated @RequestBody InspectionTemplateItemRel resources){
        inspectionTemplateItemRelService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @Log("删除InspectionTemplateItemRel")
    @DeleteMapping(value = "/inspectionTemplateItemRel/{id}")
    @PreAuthorize("hasAnyRole('ADMIN','INSPECTIONTEMPLATEITEMREL_ALL','INSPECTIONTEMPLATEITEMREL_DELETE')")
    public ResponseEntity delete(@PathVariable Long id){
        inspectionTemplateItemRelService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}